__author__ = 'Administrator'
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from pages.BasePage import BasePage


class NewMessageLocators(object):
    MESSAGE_TO = (By.ID, "divTo")
    MESSAGE_SUBJECT = (By.ID, "txtSubj")
    MESSAGE_BODY = (By.XPATH, "//*[@ocsi=1]")
    SEND_BUTTON = (By.ID, "divToolbarButtonsend")
    MESSAGE_BODY_FRAME = "ifBdy"


class NewMessage(BasePage):
    def __init__(self, driver):
        super(NewMessage, self).__init__(driver)
        self.driver.switch_to.window(self.driver.window_handles[1])

    def type_message_recepient(self, recepient):
        self.driver.switch_to.window(self.driver.window_handles[1])
        self.find_element(NewMessageLocators.MESSAGE_TO).send_keys(recepient)

    def type_message_subject(self, subject):
        self.find_element(NewMessageLocators.MESSAGE_SUBJECT).send_keys(subject)

    def click_send_message(self):
        self.driver.switch_to.window(self.driver.window_handles[1])
        self.find_element(NewMessageLocators.SEND_BUTTON).click()

    def type_message_body(self, body):
        self.driver.switch_to_frame(NewMessageLocators.MESSAGE_BODY_FRAME)
        self.find_element(NewMessageLocators.MESSAGE_BODY).send_keys(body)